<?php

class YoutubeChannelControllerCore extends FrontController
{

    public $php_self = 'youtubechannel.php';
	
	public function setMedia()
	{
		parent::setMedia();
		if (version_compare(_PS_VERSION_,'1.5','<'))
		{
    		Tools::addJS(_MODULE_DIR_.'youtubechannel/js/youtubechannel.js');
    	}
		else
		{
			$this->addJS(_MODULE_DIR_.'youtubechannel/js/youtubechannel.js');	
		}
	}
    
	//PS 1.4
	public function process()
	{
		parent::process();

		$yt_user = Configuration::get('YT_USER');
		$yt_display_videos = Configuration::get('YT_DISPLAY_VIDEOS');
		$yt_desc_trunc = Configuration::get('YT_DESC_TRUNC');
		$yt_html5 = Configuration::get('YT_HTML5');
		$yt_player_width = Configuration::get('YT_PLAYER_WIDTH');
		$yt_player_height = Configuration::get('YT_PLAYER_HEIGHT');
		$yt_auto_play = Configuration::get('YT_AUTO_PLAY');
		$modulecolor = Configuration::get('YT_MODULE_COLOR');
		$iconcolor = Configuration::get('YT_ICON_COLOR');

		if (isset($modulecolor) && $modulecolor == 1){
		    $theme = 'dark';
        }
        else $theme = 'light';

	    if (isset($iconcolor) && $iconcolor == 1){
            $progressbar = 'red';
        }
        else $progressbar = 'white';

		self::$smarty->assign(array(
		    'yt_user' => $yt_user,
		    'yt_display_videos' => $yt_display_videos,
			'yt_desc_trunc' => $yt_desc_trunc,
		    'yt_html5' => $yt_html5,
		    'yt_player_width' => $yt_player_width,
		    'yt_player_height' => $yt_player_height,
		    'yt_auto_play' => $yt_auto_play,
	        'theme' => $theme,
	        'progressbar' => $progressbar
	    ));
	}

	public function displayContent()
    {
		parent::displayContent();

        self::$smarty->display(_PS_MODULE_DIR_.'youtubechannel/youtubechannel_page.tpl');
    }
	
	//PS 1.5
	public function initContent()
	{
		parent::initContent();

		$yt_user = Configuration::get('YT_USER');
		$yt_display_videos = Configuration::get('YT_DISPLAY_VIDEOS');
		$yt_desc_trunc = Configuration::get('YT_DESC_TRUNC');
		$yt_html5 = Configuration::get('YT_HTML5');
		$yt_player_width = Configuration::get('YT_PLAYER_WIDTH');
		$yt_player_height = Configuration::get('YT_PLAYER_HEIGHT');
		$yt_auto_play = Configuration::get('YT_AUTO_PLAY');
		$modulecolor = Configuration::get('YT_MODULE_COLOR');
		$iconcolor = Configuration::get('YT_ICON_COLOR');

		if (isset($modulecolor) && $modulecolor == 1){
		    $theme = 'dark';
        }
        else $theme = 'light';

	    if (isset($iconcolor) && $iconcolor == 1){
            $progressbar = 'red';
        }
        else $progressbar = 'white';

		self::$smarty->assign(array(
		    'yt_user' => $yt_user,
		    'yt_display_videos' => $yt_display_videos,
			'yt_desc_trunc' => $yt_desc_trunc,
		    'yt_html5' => $yt_html5,
		    'yt_player_width' => $yt_player_width,
		    'yt_player_height' => $yt_player_height,
		    'yt_auto_play' => $yt_auto_play,
	        'theme' => $theme,
	        'progressbar' => $progressbar
	    ));

		$this->setTemplate(_PS_MODULE_DIR_.'youtubechannel/youtubechannel_page.tpl');
	}
}